package com.example.controller;

import com.example.pojo.Account;
import com.example.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@RequestMapping("/account")
@Controller
public class AccountController {

    @Autowired
    private AccountService accountService;

    @RequestMapping("/save")
    @ResponseBody
    public String save(Account account) {
        boolean save = accountService.save(account);
        System.out.println("这是controller");
        return save ? "保存成功":"保存失败";
    }

    @RequestMapping("findAll")
    public ModelAndView findAll() {
        ModelAndView modelAndView = new ModelAndView();
        List<Account> list = accountService.findAll();
        modelAndView.addObject("list",list);
        modelAndView.setViewName("accountList");
        return modelAndView;
    }
}
